/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.moveclock.views;

// Need the following import to get access to the app resources, since this
// class is in a sub-package.
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;


/**
 * Example of how to write a custom subclass of View. JoystickView
 * is used to draw simple text views. Note that it does not handle
 * styled text or right-to-left writing systems.
 *
 */
public class CircuitOfJoystickView extends View {

    
    private Paint mPaint;
    private RectF mOval;
    
    /**
     * Constructor.  This version is only needed if you will be instantiating
     * the object manually (not from a layout XML file).
     * @param context
     */
    public CircuitOfJoystickView(Context context) {
        super(context);
        initView();
    }
    
	/**
     * Construct object, initializing with any attributes we understand from a
     * layout file. These attributes are defined in
     * SDK/assets/res/any/classes.xml.
     * 
     * @see android.view.View#View(android.content.Context, android.util.AttributeSet)
     */
    public CircuitOfJoystickView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
        
    }


    private final void initView() {
         
         mPaint = new Paint();
         mPaint.setColor(0x88888888);
         mPaint.setStyle(Paint.Style.STROKE);
         mPaint.setStrokeWidth(4);
         mPaint.setAntiAlias(true);
         
         mOval = new RectF(10, 10, 210, 210);
    }
    
    private void drawArcs(Canvas canvas, RectF oval, boolean useCenter,
            Paint paint) {
    	canvas.drawArc(oval, 0, 360, useCenter, paint);
}

    /**
     * @see android.view.View#measure(int, int)
     */
    
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(measureWidth(widthMeasureSpec),
                measureHeight(heightMeasureSpec));
    }

    /**
     * Determines the width of this view
     * @param measureSpec A measureSpec packed into an int
     * @return The width of the view, honoring constraints from measureSpec
     */
    
    private int measureWidth(int measureSpec) {
        return 220;
    }

    /**
     * Determines the height of this view
     * @param measureSpec A measureSpec packed into an int
     * @return The height of the view, honoring constraints from measureSpec
     */
    
    private int measureHeight(int measureSpec) {
        return 220;
    }
    

    /**
     * Render the text
     * 
     * @see android.view.View#onDraw(android.graphics.Canvas)
     */
    
    @Override protected void onDraw(Canvas canvas) {
        drawArcs(canvas, mOval, true, mPaint);
        invalidate();
    }
    
}
